package com.zhangyujun.bysj.manager.controller;
import com.github.pagehelper.PageInfo;

import com.zhangyujun.bysj.manager.service.SysUserService;
import com.zhangyujun.bysj.model.dto.system.AssignRoleDto;
import com.zhangyujun.bysj.model.dto.system.SysUserDto;
import com.zhangyujun.bysj.model.entity.system.SysRole;
import com.zhangyujun.bysj.model.entity.system.SysUser;
import com.zhangyujun.bysj.model.vo.common.Result;
import com.zhangyujun.bysj.model.vo.common.ResultCodeEnum;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/admin/system/sysUser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService ;
    //用户分页查询
    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysRole>> findByPage(SysUserDto sysUserDto ,
                                                @PathVariable(value = "pageNum") Integer pageNum ,
                                                @PathVariable(value = "pageSize") Integer pageSize) {
        PageInfo<SysUser> pageInfo = sysUserService.findByPage(sysUserDto , pageNum , pageSize) ;
        return Result.build(pageInfo , ResultCodeEnum.SUCCESS) ;
    }
    //用户添加
    @PostMapping(value = "/saveSysUser")
    public Result<SysUser> saveSysUser(@RequestBody SysUser sysUser) {
        sysUserService.saveSysUser(sysUser) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
    //用户修改
    @PutMapping(value = "/updateSysUser")
    public Result<SysUser> updateSysUser(@RequestBody SysUser sysUser) {
        sysUserService.updateSysUser(sysUser) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
    //删除用户
    @DeleteMapping(value = "/deleteSysUser/{userId}")
    public Result<SysUser> deleteSysUser(@PathVariable(value = "userId") Long userId) {
        sysUserService.deleteById(userId) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
    //用户分配角色
    //保存分配数据
    @PostMapping(value = "/doAssign")
    public Result<SysUser> doAssign(@RequestBody AssignRoleDto assignRoleDto) {
        sysUserService.doAssign(assignRoleDto) ;
        return Result.build(null , ResultCodeEnum.SUCCESS) ;
    }
}